package com.testapp.bluetoothtest08.File;

import java.io.File;

public class ScanMachineFile {
    File num[]=new File[14];
    File time[]=new File[14];
    File index = new File("/data/data/com.testapp.bluetoothtest08/scanIndex.txt");

    BaseFileOperation bfo = new BaseFileOperation();

    public ScanMachineFile(){
        init();
    }

    public void clearAll(){
        bfo.write(index,"");
        for (int i = 0; i < 14; i++) {
            bfo.write(num[i],"");
        }
        for (int i = 0; i < 14; i++) {
            bfo.write(time[i],"");
        }

    }

    void init (){
        for (int i = 0; i < 14; i++) {
            num[i] = new File("/data/data/com.testapp.bluetoothtest08/dataDay"+i+".txt");//存放每天的设备
            if(!bfo.isExist(num[i])){
                bfo.write(num[i],"");
            }
        }
        for (int i = 0; i < 14; i++) {
            time[i] = new File("/data/data/com.testapp.bluetoothtest08/timeDay"+i+".txt");//存放每天的设备
            if(!bfo.isExist(time[i])){
                bfo.write(time[i],"");
            }
        }
        if(!bfo.isExist(index)){
            bfo.write(index,"");
        }
    }

    public void writeData(int index, String data){
        bfo.writeAppend(num[index],data);
    }

    public String readData(int index){
        return bfo.readString(num[index]);
    }




    //写时间
    public void writeTime(int i) {
        long createdTime = System.currentTimeMillis();
        bfo.write(time[i], Long.toString(createdTime));
    }

    //读时间
    public long readTime(int i) {
        return bfo.readLong(time[i]);
    }

    //写天数
    public void writeIndex(int day) {
        bfo.write(index, Integer.toString(day));
    }

    //读天数
    public int readIndex() {
        return bfo.readInt(index);
    }


    public void clearTime(int index){
        bfo.write(time[index],"");
    }
    public void clearData(int index){
        bfo.write(num[index],"");
    }


}
